package Messages;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import ocsf.server.ConnectionToClient;
import server.EchoServer;
import server.SQLConnection;

public class MessageLendReport implements Runnable{
	/**
	 * this class implements the lend report 
	 * @author Ron Shenkerman
	 * @author Gabi Revah
	 * @author Aviad Almog
	 * @author Ivan Onyshchenko
	 */
	
	private int difwanted;
	private int difnormal;
	private int row1,i;
	Statement stmt;
	String no="no";
	//PreparedStatement ps;
	private static final int oneday=86400000;
	private ConnectionToClient client;
	public MessageLendReport() {
		super();
		this.client = client;
	}
	/**
	 * 
	 * @return the number of the wanted book was lended 
	 */
	public int getDifwanted() {
		return difwanted;
	}
	/**
	 * 
	 * @param set the book the number of wanted book was lended
	 */
	public void setDifwanted(int difwanted) {
		this.difwanted = difwanted;
	}
	/**
	 * 
	 * @return the number of the normal book was lended  
	 */
	public int getDifnormal() {
		return difnormal;
	}
	/**
	 * 
	 * @param set the book the number of normal book was lended
	 */
	public void setDifnormal(int difnormal) {
		this.difnormal = difnormal;
	}
	@SuppressWarnings("deprecation")
	@Override
	public void run() {
		while(EchoServer.echoserveron){
		int countday=1;
		System.out.println("generating day lending report");
		
		
		try 
		{

			System.out.println("extending lend");
			String y="no";
			SQLConnection conn = new  SQLConnection();
			stmt = conn.getConnection().createStatement();
			ResultSet rs= stmt.executeQuery("SELECT * FROM db1.lending WHERE lending.lend='"+y+"';");
			
				try {
				
						while (rs.next())//check if subscriber lended this book
							{
								
								i++;
								System.out.println(i);
						
							}
						
				}
						catch (SQLException e)
								{	
								e.printStackTrace();
								}
		
  
		
		
		
		
		
		/*try 
		{
			Thread.sleep(2000);
			countday=1;
			
		} 
		catch (InterruptedException e) 
		{
			e.printStackTrace();
		}*/
	
	
	}
		catch (Exception ex )
		{
	  ex.printStackTrace();
		}
	}
	
	
	
 }
}

